var Main = function () {
	"use strict";
	this.input = $('#inputBox');
	this.enemies = [];
	this.bolds = [];
	Main.prototype.init = function () {
		var i, timer;
		this.input.focus();
		for (i = 0; i < 5; i += 1) {
			this.enemies.push(new Enemy($('#enemies'), i));
		}
		this.input.keyup(function (event) {
			this.processInput(event);
		}.bind(this));
		
		timer = setInterval(function () {
			this.enemies.push(new Enemy($('#enemies'), this.enemies.length));
			if (Dictionary.length <= 0) {
				clearInterval(timer);
			}
		}.bind(this), 2000);
	};
	Main.prototype.processInput = function (event) {
		var i, text = this.input.attr('value');
		if (text !== null && text !== undefined && text.length > 0) {
			if (event.keyCode === 13) {
				for (i = 0; i < this.enemies.length; i += 1) {
					this.enemies[i].processWord(text);
				}
				this.input.attr('value', '');
				this.clearBolds();
			} else {
				for (i = 0; i < this.enemies.length; i += 1) {
					this.bolds = this.bolds.concat(this.enemies[i].embolden(text));
				}
			}
		} else {
			this.clearBolds();
		}
	};
	Main.prototype.clearBolds = function () {
		var i;
		for (i = 0; i < this.bolds.length; i += 1) {
			this.bolds[i].unEmbolden();
		}
	};
};

var a = new Main();
a.init();